package com.droid.lib.controls.widget;

import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

public class PathItem {
    /**
     * 地图的点击范围
     */
    private RectF mapRectF;
    /**
     * 文字中心位置
     */
    private Location textLocation;
    /**
     * 圆点中心位置
     */
    private Location circleLocation;
    /**
     * 地图区域的名称
     */
    private String mapName;
    /**
     * 地图区域Path
     */
    private Path mapPath;
    /**
     * 地图颜色
     */
    private int mapColor;
    /**
     * 地图文字颜色
     */
    private int mapTextColor;
    /**
     * 地图文字大小
     */
    private int dataMapSize = 10;
    /**
     * 地图圆半径
     */
    private float dataMapRadius;
    /**
     * 地图圆形颜色
     */
    private int mapCircleColor;

    /**
     * 点击范围
     */
    private MapRegion mapRegion;

    public MapRegion getMapRegion() {
        return mapRegion;
    }

    public void setMapRegion(MapRegion mapRegion) {
        this.mapRegion = mapRegion;
    }

    public int getMapCircleColor() {
        return mapCircleColor;
    }

    public void setMapCircleColor(int mapCircleColor) {
        this.mapCircleColor = mapCircleColor;
    }

    public Location getCircleLocation() {
        return circleLocation;
    }

    public void setCircleLocation(Location circleLocation) {
        this.circleLocation = circleLocation;
    }

    public float getDataMapRadius() {

        return dataMapRadius;
    }


    public void setDataMapRadius(float dataMapRadius) {
        float circleX = circleLocation.getX();
        float circleY = circleLocation.getY();
        float top = mapRectF.top;
        float bottom = mapRectF.bottom;
        float left = mapRectF.left;
        float right = mapRectF.right;
        float marginTop = Math.abs(circleY - top);
        float marginBottom = Math.abs(circleY - bottom);
        float marginLeft = Math.abs(circleX - left);
        float marginRight = Math.abs(circleX - right);
        Float[] numbers = {marginTop, marginBottom, marginLeft, marginRight};
        float min = Collections.min(Arrays.asList(numbers));
        if(dataMapRadius>1){
            this.dataMapRadius = dataMapRadius/100*min;
        }else {
            this.dataMapRadius = dataMapRadius*min;
        }

    }

    static class XComparator implements Comparator {
        public int compare(Object object1, Object object2) {// 实现接口中的方法
            Location p1 = (Location) object1; // 强制转换
            Location p2 = (Location) object2;
            return Float.compare(p1.getX(), p2.getX());
        }
    }

    static class YComparator implements Comparator {
        public int compare(Object object1, Object object2) {// 实现接口中的方法
            Location p1 = (Location) object1; // 强制转换
            Location p2 = (Location) object2;
            return Float.compare(p1.getY(), p2.getY());
        }
    }

    public int getMapColor() {
        return mapColor;
    }

    public void setMapColor(int mapColor) {
        this.mapColor = mapColor;
    }

    public String getMapName() {
        return mapName;
    }

    public void setMapName(String mapName) {
        this.mapName = mapName;
    }

    public RectF getMapRectF() {
        return mapRectF;
    }

    public void setMapRectF(RectF mapRectF) {
        this.mapRectF = mapRectF;
    }


    public Path getMapPath() {
        return mapPath;
    }

    public void setMapPath(Path mapPath) {
        this.mapPath = mapPath;
    }

    public Location getTextLocation() {
        return textLocation;
    }

    public void setTextLocation(Location textLocation) {
        this.textLocation = textLocation;
    }

    public int getMapTextColor() {
        return mapTextColor;
    }

    public void setMapTextColor(int mapTextColor) {
        this.mapTextColor = mapTextColor;
    }

    public int getDataMapSize() {
        return dataMapSize;
    }

    public void setDataMapSize(int dataMapSize) {
        this.dataMapSize = dataMapSize;
    }

    public static class Location {

        private float x;
        private float y;

        public Location(float x, float y) {
            this.x = x;
            this.y = y;
        }

        public float getX() {
            return x;
        }

        public void setX(float x) {
            this.x = x;
        }

        public float getY() {
            return y;
        }

        public void setY(int y) {
            this.y = y;
        }
    }
}
